var vm = new Vue({
    el: "#app",
    data: {
        user: "",
        password: "",
        prop: "",
        srcs: [
           { src:"../static/img/xiaoji.jpg",id:0},
           { src:"../static/img/xiaojiejiea.jpg",id:1},
           { src:"../static/img/xiaojiejie_1.jpg",id:2},
           { src:"../static/img/xiaojiejie_2.jpg",id:3} 
        ],
        mark: 0,
        timer: null
    },
    components: {
        "header-com" : headerCom,
        "clock-com" : clockCom,
        "popup-com" : popupCom
    },
    methods: {
        verification: function() {
            let datas = Qs.stringify({
                "cardNo" : this.user,
                "password" : this.password
            })
            var reg = /^\d{19}$/g;
            var reg_2 = /^\d{6}$/g
            if(this.user == ""){
                this.prop = "请输入用户名";
                return;
            }
            if(!reg.test(this.user)) {
                this.prop = "账号错误！请输入19位数字";
                return;
            }
            if(this.password == ""){
                this.prop = "密码为空！请输入密码";
                return;
            }
            if(!reg_2.test(this.password)){
                this.prop = "密码格式错误！请输入6位数字密码";
                return;
            }
            document.getElementById("login").disabled = "disabled";//禁止多次点击
            axios.post("/tokens/login",datas)
            .then((res)=> {
                var code = res.data.code;
                document.getElementById("login").disabled = "";//按钮可点击
                switch (code) {
                    case 113:
                    this.prop = "账号不存在";
                    break;
                    case 123:
                    this.prop = "密码错误,错误三次将被冻结!";
                    break;
                    case 0:
                    window.location.href = "./loading";
                    break;
                    case 114:
                    window.location.href = "./frozen";
                    break;
                    case 100:
                    this.prop = "登录异常";
                    break;
                    case 1:
                    this.prop = "数据异常";
                    break;
                }                
            })
            .catch(function(error) {
                alert(error);
            })
        },
        autoplay() {
            this.mark ++;
            if(this.mark > this.srcs.length-1) {
                this.mark = 0;
                console.log("1");
            }
        },
        play() {
            this.timer = setInterval(this.autoplay,2500);
        },
        stop() {
            clearInterval(this.timer);
        },
        closeAccount() {
            this.user = "";
        },
        closePassword() {
            this.password = "";
        }
    },
    created() {
        this.play();
    },
});